package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FileDistribution;
import com.amsp.oa.oademo.service.FileDistributionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件发放与回收管理")
@RestController
@RequestMapping("/api/fileDistribution")
public class FileDistributionController {

    @Autowired
    private FileDistributionService fileDistributionService;

    @ApiOperation("分页查询文件发放记录")
    @GetMapping("/page")
    public ResponseEntity<IPage<FileDistribution>> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("搜索关键字") @RequestParam(required = false) String keyword) {
        return ResponseEntity.ok(fileDistributionService.getPage(current, size, keyword));
    }

    @ApiOperation("获取文件发放记录详情")
    @GetMapping("/{id}")
    public ResponseEntity<FileDistribution> getDetail(@PathVariable Long id) {
        return ResponseEntity.ok(fileDistributionService.getDetailById(id));
    }

    @ApiOperation("保存或更新文件发放记录")
    @PostMapping("/save")
    public ResponseEntity<Boolean> save(@RequestBody FileDistribution fileDistribution) {
        return ResponseEntity.ok(fileDistributionService.saveOrUpdateDistribution(fileDistribution));
    }

    @ApiOperation("删除文件发放记录")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable Long id) {
        return ResponseEntity.ok(fileDistributionService.removeById(id));
    }
}